package com.noble.glamour.ui.fragment.video;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.noble.glamour.R;
import com.noble.glamour.module.logic.baseui.BaseFragment;
import com.noble.glamour.ui.user.my.adapter.ViewGroupPagerAdapter;
import com.noble.library.controls.smarttablayout.PagerItem;
import com.noble.library.controls.smarttablayout.SmartTabLayout;
import com.noble.library.view.base.BasePanel;

import java.util.ArrayList;
import java.util.List;

/**
 * 女性：视频集
 * Created by Su on 2017/11/13.
 */
public class VideoFragment extends BaseFragment {

    private SmartTabLayout stlTitles;
    private ViewPager vpViewChange;
    private List<PagerItem> listViews;//pagerItem集合
    private List<BasePanel> panls = new ArrayList<>(); // Tab页面列表

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.video_collection);
        initTitle();
        initView();
        return getContentView();
    }

    private void initView() {

        stlTitles = (SmartTabLayout) findViewById(R.id.my_attention_stl_titles);
        vpViewChange = (ViewPager) findViewById(R.id.my_attention_vPager);
        initViewsList();
        initViewPager();
        ((LinearLayout) stlTitles.getTabStrip()).setGravity(Gravity.CENTER_HORIZONTAL);//标题居中
        stlTitles.setCustomTabView(R.layout.f1_custom_table_view, R.id.tv_left_tab);//设置自定义标题
        stlTitles.setViewPager(vpViewChange);//设置viewpager
        stlTitles.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }

    private void initTitle() {
        setTitle("视频集");
    }

    /**
     * 添加展示panel
     */
    private void initViewsList() {
        listViews = new ArrayList<>();

        panls.add(new VideoRecordPanel(getContext()));
        panls.add(new VideoManagePanel(getContext()));
        listViews.add(new PagerItem("录制视频", panls.get(0).getContentView()));
        listViews.add(new PagerItem("管理视频", panls.get(1).getContentView()));
    }

    private void initViewPager() {
        vpViewChange.setAdapter(new ViewGroupPagerAdapter(listViews));
    }
}
